/*
 * 	INFO :
 * 		the file implement the simple ip route table with hash
 *              add ,delete ,find ,cout the item in the route table
 *
 * 	Author: 
 * 		mark <mark199312@gmail.com>
 *
 */
#include<stdlib.h>
#include"ip_table.h"
#include"log.h"

/*
 *is to add key into a hash table;
 */

void Fib_add_hash(struct fib **head,struct fib *p)
{
        struct fib *temp;

        HASH_FIND(hh,*head,p,sizeof(record_key_t),temp);

        if(temp!=NULL)
        {
                return;
        }
        
        HASH_ADD(hh,*head,key,sizeof(record_key_t),p);
}       

/*
 *is to find a specific packet by key
 */

struct sockaddr_in * Fib_find_hash(struct fib * head,record_key_t *p)
{
        struct fib *temp;
        HASH_FIND(hh,head,p,sizeof(record_key_t),temp);

        if(temp==NULL)
        {
                return NULL;
        }
        else
        {
                return temp->node;
        }
}

/*
 *is to delete a specific packet by key
 */

void Fib_delete_hash(struct fib **head,record_key_t *p)
{
        struct fib *temp;

        HASH_FIND(hh,*head,p,sizeof(record_key_t),temp);

        HASH_DEL(*head,temp);

        free(temp);
}

/*
 *is for count hash size
 */

int Fib_count_hash(struct fib *head)
{
        int num=0;
        num=HASH_COUNT(head);
        return num;
}

/*
 *is the tool to print the fib
 */

void Fib_print_fib(struct fib *head)
{
        struct fib *f;

        for(f=head;f!=NULL;f=f->hh.next)
        {
                log_info("");
        }       
}
